# -*- coding: utf-8 -*-
from selenium import webdriver
import sys,time
reload(sys)
sys.setdefaultencoding('utf-8')

# 智能等待，直到找到所需控件
def smwait(method,element):
    for i in range(10):
        if i >= 9 : 
            print "find element timeout!"   
            break
        try: 
            # if driver.find_element_by_id(element):
            if method(element):
                break
        except:
            # print "wait for find element"
            pass
        # print i
        time.sleep(1)

if __name__=='__main__':
    driver=webdriver.Firefox()
    smwait(driver.find_element_by_id,"1234")
    print 'test finish'